#!/usr/bin/env python

import wx
import component

class Main(component.Interactor):
    '''Main class
    
    @author Julot <andy.julot@gmail.com>
    @since Saturday, January 14, 2012. 09:04 AM'''
    
    def bind(self):
        super(Main, self).bind()
        view = self.view
        menu = view.MenuBar
        tool = view.ToolBar
        
        view.titles.Bind(wx.EVT_LIST_ITEM_SELECTED, self.selectTitle)
        
        view.Bind(wx.EVT_MENU, self.mold, menu.file.mold)
        view.Bind(wx.EVT_MENU, self.close, menu.file.close)
        view.Bind(wx.EVT_MENU, self.setupPrinter, menu.file.printerSettings)
        view.Bind(wx.EVT_MENU, self.importXml, menu.aniDb.importXml)
        view.Bind(wx.EVT_MENU, self.downloadXml, menu.aniDb.downloadXml)
        view.Bind(wx.EVT_MENU, self.downloadImage, menu.aniDb.downloadImage)
        view.Bind(wx.EVT_MENU, self.showAbout, menu.help.about)
        
        view.Bind(wx.EVT_MENU, self.mold, tool.mold)
        view.Bind(wx.EVT_MENU, self.downloadXml, tool.downloadXml)
        view.Bind(wx.EVT_MENU, self.downloadImage, tool.downloadImage)
        view.Bind(wx.EVT_MENU, self.showAbout, tool.about)
        view.Bind(wx.EVT_MENU, self.close, tool.close)
    
    def selectTitle(self, event):
        self.presenter.show(event.m_item.Data)
    
    def importXml(self, event):
        result = self.presenter.confirmImportXml()
        if result:
            self.presenter.importXml(result)
            self.presenter.populateTitles()

    def mold(self, event):
        self.presenter.mold()
    
    def downloadXml(self, event):
        if self.presenter.confirmDownloadXml():
            self.presenter.downloadXml()
            self.presenter.downloadImage()
            self.presenter.show()
    
    def downloadImage(self, event):
        if self.presenter.confirmDownloadImage():
            self.presenter.downloadImage()
            self.presenter.show()
    
    def showAbout(self, event):
        self.presenter.showAbout()
    
    def close(self, event):
        self.presenter.close()
    
    def setupPrinter(self, event):
        self.presenter.setupPrinter()
    